/**
 * js版Map
 */
function Map() {

	/**  
     * struct  
	 * 存放键值的数组
     */
	var struct = function(key, value) {
		this.key = key;
		this.value = value;
	}

	/**  
     * override put   
	 * 放入一个键值对  
     * @param {String} key  
     * @param {Object} value
     */
	var put = function(key, value) {
		for (var i = 0; i < this.arr.length; i++) {
			if (this.arr[i].key === key) {
				this.arr[i].value = value;
				return;
			}
		}
		this.arr[this.arr.length] = new struct(key, value);
	}

	/**  
     * override get   
	 * 获取某键对应的值
	 * @param {String} key  
     * @param {Object} value
     */
	var get = function(key) {
		for (var i = 0; i < this.arr.length; i++) {
			if (this.arr[i].key === key) {
				return this.arr[i].value;
			}
		}
		return null;
	}

	/**  
     * override remove   
	 * 删除一个键值对  
	 * @param {String} key 
     */
	var remove = function(key) {
		var v;
		for (var i = 0; i < this.arr.length; i++) {
			v = this.arr.pop();
			if (v.key === key) {
				continue;
			}
			this.arr.unshift(v);
		}
	}

	/**  
     * override size   
	 * 获取键值对数量
     */  
	var size = function() {
		return this.arr.length;
	}

	/**  
     * override isEmpty   
	 * 判断Map是否为空
     */  
	var isEmpty = function() {
		return this.arr.length <= 0;
	}

	/**  
     * override toString
	 * 重写toString
     */  
    var toString = function(){   
        var s = "{";   
		var size = this.arr.length;
		for (var i = 0; i < size; i++) {
			s += this.arr[i].key + "=" + this.arr[i].value;
			if (i < size-1) {
				s += ", ";
			}
		}
        s+="}";   
        return s;   
    }

	this.arr = new Array();
	this.get = get;
	this.put = put;
	this.remove = remove;
	this.size = size;
	this.isEmpty = isEmpty;
	this.toString = toString;
}

Date.prototype.format = function(mask) {      
	var d = this;      
	var zeroize = function (value, length) {      
		if (!length) {
			length = 2;
		}
		value = String(value);      
		for (var i = 0, zeros = ''; i < (length - value.length); i++) {      
			zeros += '0';      
		}      
		return zeros + value;      
	};   
	// 默认格式
	if (mask == null) {
		mask = "yyyy-MM-dd hh:mm:ss";
	}
	return mask.replace(/"[^"]*"|'[^']*'|\b(?:d{1,4}|m{1,4}|yy(?:yy)?|([hHMstT])\1?|[lLZ])\b/g, function($0) {     
		switch($0) {      
			case 'd':   return d.getDate();      
			case 'dd':  return zeroize(d.getDate());      
			case 'ddd': return ['Sun','Mon','Tue','Wed','Thr','Fri','Sat'][d.getDay()];      
			case 'dddd':    return ['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'][d.getDay()];      
			case 'M':   return d.getMonth() + 1;      
			case 'MM':  return zeroize(d.getMonth() + 1);      
			case 'MMM': return ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'][d.getMonth()];      
			case 'MMMM':    return ['January','February','March','April','May','June','July','August','September','October','November','December'][d.getMonth()];      
			case 'yy':  return String(d.getFullYear()).substr(2);      
			case 'yyyy':    return d.getFullYear();      
			case 'h':   return d.getHours() % 12 || 12;      
			case 'hh':  return zeroize(d.getHours() % 12 || 12);      
			case 'H':   return d.getHours();      
			case 'HH':  return zeroize(d.getHours());      
			case 'm':   return d.getMinutes();      
			case 'mm':  return zeroize(d.getMinutes());      
			case 's':   return d.getSeconds();      
			case 'ss':  return zeroize(d.getSeconds());      
			case 'l':   return zeroize(d.getMilliseconds(), 3);      
			case 'L':   var m = d.getMilliseconds();      
					if (m > 99) {
						m = Math.round(m / 10);
					}
					return zeroize(m);      
			case 'tt':  return d.getHours() < 12 ? 'am' : 'pm';      
			case 'TT':  return d.getHours() < 12 ? 'AM' : 'PM';      
			case 'Z':   return d.toUTCString().match(/[A-Z]+$/);      
			// Return quoted strings with the surrounding quotes removed      
			default:    return $0.substr(1, $0.length - 2);      
		}      
	});      
};

//获取当前时间累加后的日期
function getPlusDate(days){     
	var dd = new Date();
	dd.setDate(dd.getDate()+parseInt(days));//获取days天后的日期
	var y = dd.getFullYear();
	var m = dd.getMonth()+1;//获取当前月份的日期
	var d = dd.getDate();
	return new Date(y+'/'+m+'/'+d);
}

//获取某天的前一天
function getYestoday(date){    
	var yesterday_milliseconds=date.getTime()-1000*60*60*24;     
	var yesterday = new Date();     
	yesterday.setTime(yesterday_milliseconds);     
	var strYear = yesterday.getFullYear();  
	var strDay = yesterday.getDate();  
	var strMonth = yesterday.getMonth()+1;
	if(strMonth<10) {  
		strMonth="0"+strMonth;  
	}  
	return new Date(strYear+'/'+strMonth+'/'+strDay);
}
  
//获得上个月在昨天这一天的日期
function getLastMonthYestoday(date){
	var daysInMonth = new Array([0],[31],[28],[31],[30],[31],[30],[31],[31],[30],[31],[30],[31]);
	var strYear = date.getFullYear();  
	var strDay = date.getDate();  
	var strMonth = date.getMonth()+1;
	if(strYear%4 == 0 && strYear%100 != 0){
		daysInMonth[2] = 29;
	}
	if(strMonth - 1 == 0) {
		strYear -= 1;
		strMonth = 12;
	} else {
		strMonth -= 1;
	}
	strDay = daysInMonth[strMonth] >= strDay ? strDay : daysInMonth[strMonth];
	if(strMonth<10){  
		strMonth="0"+strMonth;  
	}
	if(strDay<10) {  
		strDay="0"+strDay;  
	}
	return new Date(strYear+'/'+strMonth+'/'+strDay);
}

//获得上一年在昨天这一天的日期
function getLastYearYestoday(date){
	var strYear = date.getFullYear() - 1;  
	var strDay = date.getDate();  
	var strMonth = date.getMonth()+1;
	if(strMonth<10) {  
		strMonth="0"+strMonth;  
	}
	if(strDay<10){  
		strDay="0"+strDay;  
	}
	return new Date(strYear+'/'+strMonth+'/'+strDay);
}

//获得上周第一天
function getPrevWeekFirstDate () {
	//今天时间：
	var today = new Date();
	var year=today.getFullYear();
	var month=today.getMonth()+1;
	var day=today.getDate();
	var thisWeekStart; //本周周一的时间
	if(today.getDay()==0){  //周天的情况；
		thisWeekStart = (new Date(year+'/'+month+'/'+day)).getTime()-((today.getDay())+6) * 86400000;
	}else{
		thisWeekStart = (new Date(year+'/'+month+'/'+day)).getTime()-((today.getDay())-1) * 86400000;
	}
	var prevWeekStart = thisWeekStart - 7 * 86400000;//上周周一的时间
	var weekStartDate=(new Date(prevWeekStart));
	return weekStartDate;
}

//获得上周最后一天
function getPrevWeekLastDate () {
	//今天时间：
	var today = new Date();
	var year=today.getFullYear();
	var month=today.getMonth()+1;
	var day=today.getDate();
	var thisWeekEnd; //本周周一的时间
	if(today.getDay()==0){  //周天的情况；
		thisWeekEnd = (new Date(year+'/'+month+'/'+day)).getTime()-((today.getDay())+6) * 86400000;
	}else{
		thisWeekEnd = (new Date(year+'/'+month+'/'+day)).getTime()-((today.getDay())-1) * 86400000;
	}
	var prevWeekEnd = thisWeekEnd - 1 * 86400000;//上周周日的时间
	var weekStartDate=(new Date(prevWeekEnd));
	return weekStartDate;
}

//获得本周第一天
function getCurWeekFirstDate () {
	//今天时间：
	var today = new Date();
	var year=today.getFullYear();
	var month=today.getMonth()+1;
	var day=today.getDate();
	var thisWeekStart; //本周周一的时间
	if(today.getDay()==0){  //周天的情况；
		thisWeekStart = (new Date(year+'/'+month+'/'+day)).getTime()-((today.getDay())+6) * 86400000;
	}else{
		thisWeekStart = (new Date(year+'/'+month+'/'+day)).getTime()-((today.getDay())-1) * 86400000;
	}
	var weekStartDate=(new Date(thisWeekStart));
	return weekStartDate;
}

//获得本周最后一天
function getCurWeekLastDate () {
	//今天时间：
	var today = new Date();
	var year=today.getFullYear();
	var month=today.getMonth()+1;
	var day=today.getDate();
	var thisWeekEnd; //本周周一的时间
	if(today.getDay()==0){  //周天的情况；
		thisWeekEnd = (new Date(year+'/'+month+'/'+day)).getTime()-((today.getDay())+6) * 86400000;
	}else{
		thisWeekEnd = (new Date(year+'/'+month+'/'+day)).getTime()-((today.getDay())-1) * 86400000;
	}
	thisWeekEnd = thisWeekEnd + 6 * 86400000;//本周周日的时间
	var weekEndDate=(new Date(thisWeekEnd));
	return weekEndDate;
}

//获得本月第一天
function getCurMonthFirstDate () {
	var currentYear=new Date().getFullYear();
	var currentMonth=new Date().getMonth()+1;
	var prevCurrentYear=0,prevCurrentMonth=0;
	if(currentMonth==0){
		prevCurrentYear=currentYear-1;
		prevCurrentMonth=12;
	}else{
		prevCurrentYear=currentYear;
		prevCurrentMonth=currentMonth-1;
	}
	var prevmonthFirstDate=(new Date(prevCurrentYear,prevCurrentMonth,1));    
	return prevmonthFirstDate;
}

//获得本月最后一天
function getCurMonthLastDate () {
	var currentYear=new Date().getFullYear();
	var currentMonth=new Date().getMonth()+1;
	var prevCurrentYear=0,prevCurrentMonth=0;
	if(currentMonth==0){
		prevCurrentYear=currentYear-1;
		prevCurrentMonth=12;
	}else{
		prevCurrentYear=currentYear;
		prevCurrentMonth=currentMonth-1;
	}
	var prevmonthLastday=new Date((new Date(currentYear,currentMonth,1)).getTime()-86400000);
	return prevmonthLastday;
}

//获得上月第一天
function getPrevMonthFirstDate () {
	var currentYear=new Date().getFullYear();
	var currentMonth=new Date().getMonth();
	var prevCurrentYear=0,prevCurrentMonth=0;
	if(currentMonth==0){
		prevCurrentYear=currentYear-1;
		prevCurrentMonth=12;
	}else{
		prevCurrentYear=currentYear;
		prevCurrentMonth=currentMonth-1;
	}
	var prevmonthFirstDate=(new Date(prevCurrentYear,prevCurrentMonth,1));    
	return prevmonthFirstDate;
}

//获得上月最后一天
function getPrevMonthLastDate () {
	var currentYear=new Date().getFullYear();
	var currentMonth=new Date().getMonth();
	var prevCurrentYear=0,prevCurrentMonth=0;
	if(currentMonth==0){
		prevCurrentYear=currentYear-1;
		prevCurrentMonth=12;
	}else{
		prevCurrentYear=currentYear;
		prevCurrentMonth=currentMonth-1;
	}
	var prevmonthLastday=new Date((new Date(currentYear,currentMonth,1)).getTime()-86400000);
	return prevmonthLastday;
}

//获取N小时后的时间
function getAddHours(date, hours){
	var yesterday_milliseconds=date.getTime()+1000*60*60*hours;
	return new Date(yesterday_milliseconds);
}

//得到每周的第一天(周一)
function getFirstDateOfWeek(theDate){
	var firstDateOfWeek;
	theDate.setDate(theDate.getDate() + 1 - theDate.getDay()); 
	firstDateOfWeek = theDate;
	return firstDateOfWeek; 
}

//得到每周的最后一天(周日)
function getLastDateOfWeek(theDate){
	var lastDateOfWeek;
	theDate.setDate(theDate.getDate() + 7 - theDate.getDay());
	lastDateOfWeek = theDate;
	return lastDateOfWeek; 
}

//得到上周的第一天(周一)
function getPreviousFirstDateOfWeek(theDate){
	var firstDateOfWeek;
	theDate.setDate(theDate.getDate() - 6 - theDate.getDay()); 
	firstDateOfWeek = theDate;
	return firstDateOfWeek; 
}

//得到上周的最后一天(周日)
function getPreviousLastDateOfWeek(theDate){
	var lastDateOfWeek;
	theDate.setDate(theDate.getDate() +7 - theDate.getDay());
	lastDateOfWeek = theDate;
	return lastDateOfWeek; 
}

//得到某月的第一天
function getFirstDateOfMonth(date) {  
    return new Date(new Date(date.getFullYear(), date.getMonth(), 1).getTime() - 1000 * 60 * 60 * 24);  
}

//得到某月的最后一天
function getLastDateOfMonth(year, month) {  
    return new Date(new Date(date.getFullYear(), date.getMonth() + 1, 1).getTime() - 1000 * 60 * 60 * 24);  
}

//回退
function back() {
	history.go(-1);
}
//跳转url
function go(url) {
	if (url.indexOf(window.CTX_PATH) == -1) {
		url = window.CTX_PATH + "/" + url;
	}
	window.location.href=url;
}
//打开新窗口
function openWindow(url) {
	//弹出窗口的宽度;
	var iWidth = 1000;                          
	//弹出窗口的高度;
	var iHeight = 800;                        
	//获得窗口的垂直位置;
	var iTop = (window.screen.availHeight-30-iHeight)/2;       
	//获得窗口的水平位置;
	var iLeft = (window.screen.availWidth-10-iWidth)/2;
	window.open(url, 'newwindow', 'height=800, width=1000, top='+iTop+', left='+iLeft+', toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no, status=no');
} 

//校验url是否包含全角字符和空格
function checkURL1(url){
	for (var i = 0; i < url.length; i++){
    	strCode = url.charCodeAt(i);
   	 if ((strCode > 65248) || (strCode == 12288))
    	{
    		alert("URL不能包含全角字符");
        	return false;
    	}
	}
	var p0 =/[a-zA-z]+:\/\/[^\s]*/;
	if(!p0.test(url)){
		alert("请填写一个格式正确的url，协议头必须是http://  例如：http://www.baidu.com");
		return false;
	}
	var p2=/\s+/;
	if(p2.test(url)){
		alert("URL中不能包含空格");
		return false;
	}
	var p3 =url.match(/(http:\/\/)/g).length;
	if(p3>1){
		alert("只能包含一条URL");
		return false;
	}
	if(url.indexOf(";") > 0 )
	{
	    alert('URL中不能包含分号');
	    return false;
	}
	
return true;
}
//校验url是否包含全角字符和空格,中文字符
function checkURL2(url){
	for (var i = 0; i < url.length; i++){
    	strCode = url.charCodeAt(i);
   	 if ((strCode > 65248) || (strCode == 12288))
    	{
    		alert("URL不能包含全角字符");
        	return false;
    	}
	}
	var p0 =/^http+:\/\/[^\s]*/;
	if(!p0.test(url)){
		alert("请填写一个格式正确的url，协议头必须是http://  例如：http://www.baidu.com");
		return false;
	}
	var p1=/[\u4e00-\u9fa5]+/;
	if(p1.test(url)){
		alert("URL中不能包含中文字符");
		return false;
	}
	var p2=/\s+/;
	if(p2.test(url)){
		alert("URL中不能包含空格");
		return false;
	}
	var p3 =url.match(/(http:\/\/)/g).length;
	if(p3>1){
		alert("只能包含一条URL");
		return false;
	}
	if(url.indexOf(";") > 0 )
	{
	    alert('URL中不能包含分号');
	    return false;
	}
	
return true;
}